from TEST.Head.DataFrom import xls
from TEST.Head.DataWrite import new
import requests

main_url = 'https://flash.weather.com.cn/wmaps/xml/china.xml'
url = 'https://flash.weather.com.cn/wmaps/xml/'

'''读取内容'''
# value = '''<china dn="nay">
# <city quName="黑龙江" pyName="heilongjiang" cityname="哈尔滨" state1="1" state2="1" stateDetailed="多云" tem1="13" tem2="20" windState="南风转东北风3-4级"/>
# <city quName="吉林" pyName="jilin" cityname="长春" state1="1" state2="1" stateDetailed="多云" tem1="10" tem2="22" windState="小于"/>
# <city quName="辽宁" pyName="liaoning" cityname="沈阳" state1="0" state2="0" stateDetailed="晴" tem1="10" tem2="22" windState="小于"/>
# <city quName="海南" pyName="hainan" cityname="海口" state1="1" state2="1" stateDetailed="多云" tem1="25" tem2="33" windState="微风"/>
# <city quName="内蒙古" pyName="neimenggu" cityname="呼和浩特" state1="0" state2="0" stateDetailed="晴" tem1="10" tem2="23" windState="西北风3-4级"/>
# <city quName="新疆" pyName="xinjiang" cityname="乌鲁木齐" state1="0" state2="0" stateDetailed="晴" tem1="19" tem2="33" windState="微风"/>
# <city quName="西藏" pyName="xizang" cityname="拉萨" state1="7" state2="1" stateDetailed="小雨转多云" tem1="10" tem2="21" windState="微风"/>
# <city quName="青海" pyName="qinghai" cityname="西宁" state1="1" state2="1" stateDetailed="多云" tem1="5" tem2="20" windState="小于"/>
# <city quName="宁夏" pyName="ningxia" cityname="银川" state1="0" state2="0" stateDetailed="晴" tem1="13" tem2="28" windState="微风"/>
# <city quName="甘肃" pyName="gansu" cityname="兰州" state1="0" state2="0" stateDetailed="晴" tem1="11" tem2="27" windState="小于"/>
# <city quName="河北" pyName="hebei" cityname="石家庄" state1="0" state2="0" stateDetailed="晴" tem1="18" tem2="31" windState="小于"/>
# <city quName="河南" pyName="henan" cityname="郑州" state1="0" state2="0" stateDetailed="晴" tem1="21" tem2="33" windState="小于"/>
# <city quName="湖北" pyName="hubei" cityname="武汉" state1="0" state2="0" stateDetailed="晴" tem1="21" tem2="34" windState="小于"/>
# <city quName="湖南" pyName="hunan" cityname="长沙" state1="0" state2="0" stateDetailed="晴" tem1="22" tem2="35" windState="小于"/>
# <city quName="山东" pyName="shandong" cityname="济南" state1="0" state2="0" stateDetailed="晴" tem1="17" tem2="30" windState="小于"/>
# <city quName="江苏" pyName="jiangsu" cityname="南京" state1="1" state2="0" stateDetailed="多云转晴" tem1="20" tem2="32" windState="小于"/>
# <city quName="安徽" pyName="anhui" cityname="合肥" state1="0" state2="0" stateDetailed="晴" tem1="21" tem2="33" windState="小于"/>
# <city quName="山西" pyName="shanxi" cityname="太原" state1="0" state2="0" stateDetailed="晴" tem1="12" tem2="27" windState="小于"/>
# <city quName="陕西" pyName="sanxi" cityname="西安" state1="0" state2="1" stateDetailed="晴转多云" tem1="17" tem2="29" windState="小于"/>
# <city quName="四川" pyName="sichuan" cityname="成都" state1="1" state2="1" stateDetailed="多云" tem1="20" tem2="32" windState="微风"/>
# <city quName="云南" pyName="yunnan" cityname="昆明" state1="1" state2="0" stateDetailed="多云转晴" tem1="15" tem2="22" windState="小于"/>
# <city quName="贵州" pyName="guizhou" cityname="贵阳" state1="0" state2="0" stateDetailed="晴" tem1="16" tem2="30" windState="小于"/>
# <city quName="浙江" pyName="zhejiang" cityname="杭州" state1="0" state2="0" stateDetailed="晴" tem1="20" tem2="32" windState="西风3-4级转微风"/>
# <city quName="福建" pyName="fujian" cityname="福州" state1="1" state2="1" stateDetailed="多云" tem1="27" tem2="34" windState="小于"/>
# <city quName="江西" pyName="jiangxi" cityname="南昌" state1="0" state2="0" stateDetailed="晴" tem1="25" tem2="35" windState="小于"/>
# <city quName="广东" pyName="guangdong" cityname="广州" state1="1" state2="1" stateDetailed="多云" tem1="24" tem2="35" windState="微风"/>
# <city quName="广西" pyName="guangxi" cityname="南宁" state1="1" state2="0" stateDetailed="多云转晴" tem1="25" tem2="36" windState="小于"/>
# <city quName="北京" pyName="beijing" cityname="北京" state1="0" state2="0" stateDetailed="晴" tem1="14" tem2="29" windState="小于"/>
# <city quName="天津" pyName="tianjin" cityname="天津" state1="0" state2="0" stateDetailed="晴" tem1="19" tem2="29" windState="小于"/>
# <city quName="上海" pyName="shanghai" cityname="上海" state1="1" state2="0" stateDetailed="多云转晴" tem1="21" tem2="31" windState="西北风转北风4-5级"/>
# <city quName="重庆" pyName="chongqing" cityname="重庆" state1="1" state2="0" stateDetailed="多云转晴" tem1="23" tem2="36" windState="小于"/>
# <city quName="香港" pyName="xianggang" cityname="香港" state1="0" state2="0" stateDetailed="晴" tem1="27" tem2="34" windState="微风"/>
# <city quName="澳门" pyName="aomen" cityname="澳门" state1="0" state2="0" stateDetailed="晴" tem1="27" tem2="35" windState="微风"/>
# <city quName="台湾" pyName="taiwan" cityname="台北" state1="1" state2="9" stateDetailed="多云转大雨" tem1="25" tem2="29" windState="小于"/>
# <city quName="西沙" pyName="xisha" cityname="西沙" state1="1" state2="1" stateDetailed="多云" tem1="27" tem2="32" windState="小于"/>
# <city quName="南沙" pyName="nanshadao" cityname="南沙" state1="10" state2="10" stateDetailed="暴雨" tem1="27" tem2="31" windState="西南风转西风4-5级"/>
# <city quName="钓鱼岛" pyName="diaoyudao" cityname="钓鱼岛" state1="7" state2="7" stateDetailed="小雨" tem1="28" tem2="31" windState="北风3-4级转东北风4-5级"/>
# </china>'''
#
# datas = []
# while True:
#     z = value.find('quName')
#     x = value.find('pyName')
#     y = value.find('cityname')
#     if x != -1:
#         p1 = value[z+8:x-2]
#         p2 = url+value[x+8:y-2]+'.xml'
#         value = value[y+8:]
#         datas.append([p1, p2])
#     else:
#         break
#
# new('../Asset/接口测试.xls')
# exc = xls('../Asset/接口测试.xls')
# exc.write(datas,flag=1)

'''处理数据'''
# data = []
# exc = xls('../Asset/接口测试.xls')
# lis = xls('../Asset/接口测试.xls').read()
#
# for i in lis:
#     print(i[0])
#     link = requests.get(i[1])
#     text = link.text
#     x1 = text.find('>')
#     x2 = text.find('/>')
#     data.append(text[x1+1:x2])
#     link.close()
# print(data)


'''转成表格'''
excx = xls('E:\BaiduNetdiskDownload\汉科软_实训软件\项目\hkr-thr\垃圾框架\TEST\Asset\天气接口说明书.xls',1)
excc = xls('E:\BaiduNetdiskDownload\汉科软_实训软件\项目\hkr-thr\垃圾框架\TEST\Asset\接口测试.xls')
excb = xls('E:\BaiduNetdiskDownload\汉科软_实训软件\项目\hkr-thr\垃圾框架\TEST\Asset\天气接口说明书.xls')
lis = excc.read()
data = excb.read(0, 0)
datas = excx.read(0, 0)

new('E:\BaiduNetdiskDownload\汉科软_实训软件\项目\hkr-thr\垃圾框架\TEST\Asset\中央气象台天气接口说明书.xls')
exc = xls('E:\BaiduNetdiskDownload\汉科软_实训软件\项目\hkr-thr\垃圾框架\TEST\Asset\中央气象台天气接口说明书.xls')
exc.write(datas=data, row=0, col=0, index='全国天气详细信息', reverse=1)
for i in range(len(lis)):
    datas[1][0] = lis[i][0] + '天气详细信息'
    datas[1][1] = lis[i][1]
    exc.write(col=0,row=0,index=lis[i][0], datas=datas,reverse=1)

